package o;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class bnp {
    private static CountDownLatch ˋ;
    private static Map<String, Long> ˎ = new HashMap();

    static class c implements Serializable, Comparator<Entry<String, Long>> {
        private c() {
        }

        public /* synthetic */ int compare(Object obj, Object obj2) {
            return ˊ((Entry) obj, (Entry) obj2);
        }

        public int ˊ(Entry<String, Long> entry, Entry<String, Long> entry2) {
            return (int) (((Long) entry.getValue()).longValue() - ((Long) entry2.getValue()).longValue());
        }
    }

    static class e implements Runnable {
        private String ˏ;

        private e(String str) {
            this.ˏ = str;
        }

        public void run() {
            ˊ(this.ˏ);
            bnp.ˎ().countDown();
        }

        /* JADX WARNING: inconsistent code. */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        private static void ˊ(java.lang.String r7) {
            /*
            r0 = r7.isEmpty();
            if (r0 == 0) goto L_0x0007;
        L_0x0006:
            return;
        L_0x0007:
            r0 = java.net.InetAddress.getByName(r7);	 Catch:{ SecurityException -> 0x0068, UnknownHostException -> 0x0073, IllegalArgumentException -> 0x007e }
            r1 = new java.net.Socket;
            r1.<init>();
            r2 = java.lang.System.currentTimeMillis();	 Catch:{ IOException -> 0x008a }
            r4 = new java.net.InetSocketAddress;	 Catch:{ IOException -> 0x008a }
            r0 = r0.getHostAddress();	 Catch:{ IOException -> 0x008a }
            r5 = 443; // 0x1bb float:6.21E-43 double:2.19E-321;
            r4.<init>(r0, r5);	 Catch:{ IOException -> 0x008a }
            r0 = 3000; // 0xbb8 float:4.204E-42 double:1.482E-320;
            r1.connect(r4, r0);	 Catch:{ IOException -> 0x008a }
            r4 = java.lang.System.currentTimeMillis();	 Catch:{ IOException -> 0x008a }
            r2 = r4 - r2;
            r0 = o.bnc.ˎ;	 Catch:{ IOException -> 0x008a }
            r4 = "NetworkSpeedMeasurement";
            r5 = new java.lang.StringBuilder;	 Catch:{ IOException -> 0x008a }
            r5.<init>();	 Catch:{ IOException -> 0x008a }
            r6 = "cdnBackupDomain speed measure result， ";
            r5 = r5.append(r6);	 Catch:{ IOException -> 0x008a }
            r5 = r5.append(r7);	 Catch:{ IOException -> 0x008a }
            r6 = " = ";
            r5 = r5.append(r6);	 Catch:{ IOException -> 0x008a }
            r5 = r5.append(r2);	 Catch:{ IOException -> 0x008a }
            r5 = r5.toString();	 Catch:{ IOException -> 0x008a }
            r0.ˋ(r4, r5);	 Catch:{ IOException -> 0x008a }
            r0 = o.bnp.ˎ;	 Catch:{ IOException -> 0x008a }
            r2 = java.lang.Long.valueOf(r2);	 Catch:{ IOException -> 0x008a }
            r0.put(r7, r2);	 Catch:{ IOException -> 0x008a }
            r1.close();	 Catch:{ IOException -> 0x005d }
            goto L_0x0006;
        L_0x005d:
            r0 = move-exception;
            r0 = o.bnc.ˎ;
            r1 = "NetworkSpeedMeasurement";
            r2 = "socket close io exception";
            r0.ˊ(r1, r2);
            goto L_0x0006;
        L_0x0068:
            r0 = move-exception;
            r0 = o.bnc.ˎ;
            r1 = "NetworkSpeedMeasurement";
            r2 = "catch a SecurityException";
            r0.ˊ(r1, r2);
            goto L_0x0006;
        L_0x0073:
            r0 = move-exception;
            r0 = o.bnc.ˎ;
            r1 = "NetworkSpeedMeasurement";
            r2 = "catch a UnknownHostException";
            r0.ˊ(r1, r2);
            goto L_0x0006;
        L_0x007e:
            r0 = move-exception;
            r0 = o.bnc.ˎ;
            r1 = "NetworkSpeedMeasurement";
            r2 = "catch a IllegalArgumentException";
            r0.ˊ(r1, r2);
            goto L_0x0006;
        L_0x008a:
            r0 = move-exception;
            r0 = o.bnc.ˎ;	 Catch:{ all -> 0x00b6 }
            r2 = "NetworkSpeedMeasurement";
            r3 = new java.lang.StringBuilder;	 Catch:{ all -> 0x00b6 }
            r3.<init>();	 Catch:{ all -> 0x00b6 }
            r4 = "ip connect failed: ";
            r3 = r3.append(r4);	 Catch:{ all -> 0x00b6 }
            r3 = r3.append(r7);	 Catch:{ all -> 0x00b6 }
            r3 = r3.toString();	 Catch:{ all -> 0x00b6 }
            r0.ˊ(r2, r3);	 Catch:{ all -> 0x00b6 }
            r1.close();	 Catch:{ IOException -> 0x00aa }
            goto L_0x0006;
        L_0x00aa:
            r0 = move-exception;
            r0 = o.bnc.ˎ;
            r1 = "NetworkSpeedMeasurement";
            r2 = "socket close io exception";
            r0.ˊ(r1, r2);
            goto L_0x0006;
        L_0x00b6:
            r0 = move-exception;
            r1.close();	 Catch:{ IOException -> 0x00bb }
        L_0x00ba:
            throw r0;
        L_0x00bb:
            r1 = move-exception;
            r1 = o.bnc.ˎ;
            r2 = "NetworkSpeedMeasurement";
            r3 = "socket close io exception";
            r1.ˊ(r2, r3);
            goto L_0x00ba;
            */
            throw new UnsupportedOperationException("Method not decompiled: o.bnp.e.ˊ(java.lang.String):void");
        }
    }

    public String ˊ(List<String> list) {
        if (list.size() == 0) {
            return null;
        }
        if (list.size() == 1) {
            return (String) list.get(0);
        }
        ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(list.size());
        ˊ(list.size());
        for (String eVar : list) {
            if (threadPoolExecutor.submit(new e(eVar)).isDone()) {
                bnc.ˎ.ˋ("NetworkSpeedMeasurement", "future is done");
            }
        }
        try {
            ˎ().await();
            bnc.ˎ.ˋ("NetworkSpeedMeasurement", "await success");
            return ˊ(ˎ);
        } catch (InterruptedException e) {
            bnc.ˎ.ˊ("NetworkSpeedMeasurement", "catch a InterruptedException");
            return null;
        }
    }

    private String ˊ(Map<String, Long> map) {
        List<Entry> arrayList = new ArrayList(map.entrySet());
        Collections.sort(arrayList, new c());
        StringBuilder stringBuilder = new StringBuilder();
        for (Entry key : arrayList) {
            stringBuilder.append((String) key.getKey()).append(",");
        }
        if (stringBuilder.length() > 0) {
            return stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
        }
        return null;
    }

    private static CountDownLatch ˎ() {
        return ˋ;
    }

    private static void ˊ(int i) {
        ˋ = new CountDownLatch(i);
    }
}
